package 笔试.秋招2023.古茗科技;

import 题集.剑指Offer2.T06_从尾到头打印链表.ListNode;

import java.util.HashSet;
import java.util.Set;

/**
 * @author zhangconglong
 * @version [1.0.0, 2022/8/12]
 */
public class 带环单链表 {
    //方法一：快慢指针
    public void function_2(ListNode head) {


    }

    //方法二：Hash
    public boolean function_1(ListNode head) {
        Set<Integer> set = new HashSet();

        //遍历链表
        while (head!=null) {
            if(set.contains(head.val)){
                return false;
            }else {
                set.add(head.val);
            }
            if(head.next!=null){
               break;
            }
            head = head.next;
        }
        return true;
    }
}
